#pragma once

#include "Resource.h"
#include "DeclareList.h"
#include <utility/EventHandler.h>
#include <utility/String.h>
#include <vector>

// EditItemPanel dialog

namespace serika
{
	namespace ut
	{
		class Config;
	}

	namespace dq
	{
		class Item;
		class Property;
		class PropertyCtrl;

		class EditItemPanel : public CDialog, public ut::EventHandler
		{
			DECLARE_DYNAMIC(EditItemPanel)

		public:
			EditItemPanel(CWnd* pParent = NULL);   // standard constructor
			virtual ~EditItemPanel();

			// Dialog Data
			enum { IDD = IDD_EDITITEMPANEL };

			void SetItemType(int itemType);
			void SetItem(Item* item);
			Item* GetItem() const;

			virtual void Handle(const ut::Event& e);

			void OnActivate();
			void OnDeactivate();

			void DeleteProperty(PropertyCtrl* ctrl);

		protected:
			virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

			virtual BOOL OnInitDialog();
			DECLARE_MESSAGE_MAP()
			afx_msg void OnDestroy();
			afx_msg void OnTimer(UINT_PTR nIDEvent);

		private:
			Item* mItem;
			int mItemType;
			ut::Config* mConfig;
			ItemCategories mCategories;
			CComboBox mBox;

			std::vector<PropertyCtrl*> mCtrls;

			static int CTRL_BASE_Y;
			static int CTRL_HEIGHT;

			void OnLogicEvent(const ut::Event& e);
			void OnUiEvent(const ut::Event& e);
			void OnItemCategories(const ut::Event& e);
			void OnUiItemProperty(const ut::Event& e);

			void Layout();
			void LayoutItem(UINT id, const ut::Char* section);
			void Layout(CWnd* wnd, const ut::Char* section);

			void AddCtrl(Property* p);
			void MoveCtrl(int index, CWnd* wnd);
			void MoveCtrl();
			void ClearCtrl();

#ifdef LAYOUT_UI
			int mLayoutUITimer;
#endif
		};
	}
}

